package com.atguigu.gmall.seckill.service;

import com.atguigu.gmall.common.result.ResultCodeEnum;
import com.atguigu.gmall.model.activity.SeckillGoods;
import com.atguigu.gmall.model.order.OrderInfo;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fasterxml.jackson.core.JsonProcessingException;

import java.util.List;

/**
 * @author lsj
 * @create 2021-09-02 11:15
 */
public interface SeckilService extends IService<SeckillGoods> {

    List<SeckillGoods> getCurrentSeckillGoods();


    /**
     * 生成秒杀码
     * @param skuId
     * @param userId
     * @return
     */
    String generateSeckillCode(Long skuId, String userId);

    /**
     * 校验秒杀码
     * @param skuId
     * @param userId
     * @param code
     * @return
     */
    Boolean checkSeckillCode(Long skuId,String userId,String code);

    /**
     * 从本地缓存中获取所有需要秒杀的商品
     * @return
     */
    List<SeckillGoods> getCurrentSeckillGoodsFromCache();

    SeckillGoods getSeckillGoodsById(Long skuId);

    boolean checkRepeat(Long skuId, String userId, String skuIdStr);

    /**
     * 快速扣库存
     * @param skuId
     * @param userId
     * @param skuIdStr
     * @return
     */
    boolean seckillStockLocked(Long skuId, String userId, String skuIdStr);

    /**
     * 检查当前秒杀单进度
     * @param skuId
     * @param userId
     * @return
     */
    ResultCodeEnum checkOrderStatus(Long skuId, String userId) throws JsonProcessingException;

    OrderInfo getUserSeckillOrderInfo(String userId) throws JsonProcessingException;

    /**
     * 每天的盘点
     * @throws JsonProcessingException
     */
    public void clearBeforeDatas() throws JsonProcessingException;

}
